s = {'zero': 0, 'one': 1, 'two': 2, 'three': 3, 'four': 4, 'five': 5, 'six': 6, 'seven': 7, 'eight': 8, 'nine': 9}
a = input().split()
def prime(a):
    if a == 1: return False
    for i in range(2, int(a ** 0.5) + 1):
        if a % i == 0:
            return False
    return True

if len(a) == 3:
    if a[0] in s and a[1] in s and a[2] in s:
        h = ''
        f = []
        h += str(s[a[0]])
        h += str(s[a[1]])
        h += str(s[a[2]])
        g = int(h)
        for i in range(g):
            if prime(i):
                f.append(i)
        u = g
        while prime(u) is False:
            u += 1
        if u - g > g - max(f):
            print(max(f))
        elif u - g == g - max(f):
            print(max(f))
        else:
            print(u)

    else:
        print('Wrong input')
else:
    print('Wrong input')
